<template>
	<basic-container>
		<avue-form ref="form" v-model="obj" :option="option" @submit="handleSubmit">
		</avue-form>
	</basic-container>
</template>

<script>
	import * as api from '@/api/logistics/config';
	export default {
		data() {

			var validateMax = (rule, value, callback) => {
				if (value < this.obj.ssccStart) {
					callback(new Error('最大号码不能小于开始号码!'));
				} else {
					callback();
				}
			};
			return {
				obj: {},
				option: {
					group: [{
						label: 'SSCC码',
						column: [{
							labelWidth: "150",
							label: "前缀",
							prop: "ssccPre",
							rules: [{
								required: true,
								trigger: "blur"
							}]
						}, {
							labelWidth: "150",
							label: "开始号码",
							prop: "ssccStart",
							type: "number",
							rules: [{
								required: true,
								trigger: "blur"
							}]
						}, {
							labelWidth: "150",
							label: "最大号码",
							prop: "ssccMax",
							type: "number",
							rules: [{
								validator: validateMax,
								trigger: 'blur'
							}]
						}, {
							labelWidth: "150",
							label: "校验码",
							type: "radio",
							prop: "ssccCheck",
							value: 'true',
							dicData: [{
								label: '有',
								value: 'true'
							}, {
								label: '无',
								value: 'false'
							}]
						}]
					}, {
						label: '装箱建议',
						column: [{
							labelWidth: "150",
							label: "装箱规则",
							value: '1',
							dicData: [{
								label: '独色独码',
								value: '1'
							}, {
								label: '独色混码',
								value: '2'
							}, {
								label: '混色混码',
								value: '3'
							}],
							prop: "boxRule",
							type: "radio"
						}, {
							labelWidth: "150",
							label: "数量计算",
							value: '1',
							dicData: [{
								label: '体积',
								value: '1'
							}, {
								label: '重量',
								value: '2'
							}],
							prop: "numRule",
							type: "radio"
						}]
					}]
				}
			}
		},
		created() {
			this.request({
				url: '2/api/BaseCfg/pages',
				method: 'get',
				params: {
					limit: 0
				}
			}).then(res => {
				this.obj = res.data.data;
			});
		},
		methods: {
			handleSubmit(form, done) {
				return this.request({
					url: '2/api/BaseCfg/edit',
					method: 'post',
					data: this.obj
				}).then(() => {
					done();
				}, error => {
					done();
					console.log(error);
				});
			}
		}
	}
</script>

<style>
</style>
